#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <iostream>

#include "UIEventRouter.h"
#include "UIConfigResourceManager.h"
#include "UILogger.h"

#include "UIClientManager.h"
#include "UIIdentityManager.h"

/*
#include "UIApplicationManager.h"
#include "UIContextManager.h"
#include "UIDialogueManager.h"
#include "UIKnowledgeManager.h"
#include "UILanguageInterpreter.h"
#include "UIPresentationManager.h"
#include "UISpeechManager.h"
#include "UISpeechEvent.h"
*/

int main( int argc, char **argv )
{
	UILogger::create(LOGGER_LOG4CXX, "../Common/Resources/Logging/logging-log4cxx.config");
	UIConfigResourceManager::create("../Common/Resources/main-SmartHome.config", "./usersetting.config");

	/*
	UISpeechManager			*speech = NULL;
	UILanguageInterpreter	*nlu	= NULL;
	UIDialogueManager		*dm		= NULL;

	UIKnowledgeManager		*km		= NULL;
	UIApplicationManager	*am		= NULL;
	UIPresentationManager	*pm		= NULL;
	*/

	UIClientManager		*cm		= NULL;
	UIIdentityManager 	*si		= NULL;


	/*
	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_SpeechManager))
		speech = new UISpeechManager();
	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_LanguageInterpretation))
		nlu = new UILanguageInterpreter();
	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_DialogueManager))
		dm = new UIDialogueManager();
	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_ContextManager))
		cm = new UIContextManager();
	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_KnowledgeManager))
		km = new UIKnowledgeManager();
	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_ApplicationManager))
		am = new UIApplicationManager();
	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_PresentationManager))
		pm = new UIPresentationManager();
	*/

	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_ClientManager))
		cm = new UIClientManager();

	if (UIConfigResourceManager::getInstance()->isLocalModule(MODULE_IdentityManager))
		si = new UIIdentityManager();

	UIEvent eventRecogFile;
	eventRecogFile.setSender(MODULE_DialogueManager);
	eventRecogFile.setReciever(MODULE_SpeechManager);
	//eventRecogFile.setType(EVENT_IN_USER_VOICE_DATA);
		
	UIEvent eventRecogMic;
	eventRecogMic.setSender(MODULE_DialogueManager);
	eventRecogMic.setReciever(MODULE_SpeechManager);
	//eventRecogMic.setType(EVENT_IN_START_RECORDING);

	UIEvent eventTTS;
	eventTTS.setSender(MODULE_DialogueManager);
	eventTTS.setReciever(MODULE_SpeechManager);
	//eventTTS.setType(EVENT_IN_TTS_TEXT);

	UIEvent dataEvent;
	dataEvent.setSender(MODULE_DialogueManager);
	dataEvent.setReciever(MODULE_SpeechManager);
	dataEvent.setType("audio");
	unsigned char* data = new unsigned char[32];
	dataEvent.setBinaryData(data, 32);

	UILogger::getInstance()->inf(MODULE_OTHER, "SmartHome", "System started!");
	std::cout << "System started!" << std::endl;

	char t;
	int result = scanf("%c", &t);
	if (result) std::cout << "scanf error!" << std::endl;
	while (t != 'q') {
		switch (t) {
		case 'm':	// test recognize from MIC
			UIEventRouter::getInstance()->sendEvent(&eventRecogMic);
			break;
		case 'f':	// test recognize from FILE
			eventRecogFile.setValue("{\"file\":\"D:\\\\test.wav\"}");
			UIEventRouter::getInstance()->sendEvent(&eventRecogFile);
			break;	// test tts
		case 't':
			UIEventRouter::getInstance()->sendData(&dataEvent);
			break;
		default:
			;
		}
		result = scanf("%c", &t);
		if (result) std::cout << "scanf error!" << std::endl;
	}

	/*
	if (speech)	delete speech;
	if (nlu)	delete nlu;
	if (dm)		delete dm;
	if (cm)		delete cm;
	if (km)		delete km;
	if (am)		delete am;
	if (pm)		delete pm;
	*/

	if (cm)		delete cm;
	if (si)		delete si;

	UIConfigResourceManager::release();
	UIEventRouter::release();
	UILogger::release();
}
